package com.sc.thread;

/**
 * Created by Shen Chao on 2018-06-14-014.
 */
public class ThreadTest {
    public static void main(String[] args) throws Exception {
        MyThread my = new MyThread();
        my.setName("线程名字");
        //开启线程
        my.start();
        for (int i = 0; i < 10; i++) {
            System.out.print(i);
            if(i == 1) {
                //my线程执行完后，再执行主线程。因此最后输出23456789
                my.join();
            }
        }
    }
    //01执行我们的线程线程名字23456789
}

class MyThread extends Thread {
    @Override
    public void run() {
        System.out.print("执行我们的线程");
        //设置当前线程的优先级
        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
        System.out.print(Thread.currentThread().getName());
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
